#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pytz, datetime

__author__ = 'henry.woo@outlook.com'

def replace24(s):
    a=s.split(' ')
    if len(a) == 2:
        if (a[1][:2]=='24'):
            sp=a[1].split(':')
            sp[0]='00'
            s = a[0]+' '+':'.join(sp)
    return s

# t = "12/11/2013 14:30:00"
# return - datetime obj
# sg = pytz.timezone ('Asia/Singapore')
def utc2ny(t):
    #t=replace24(t)
    format="%Y-%m-%d %H:%M:%S"
    utctz = pytz.utc
    #This return value is struct_time as returned by gmtime() or localtime()
    naive = datetime.datetime.strptime(t, format)
    utcdt = utctz.localize(naive, is_dst=False)
    nytz = pytz.timezone("America/New_York")
    nytime = utcdt.astimezone(nytz)
    return nytime.strftime(format)


